<!--
 * @Description: 店铺公告审核
 * @Author: Li Yujie
 * @Date: 2021/1/29
 * @Last Modified by: Li Yujie
 * @Last Modified time: 2021/1/29
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    APP店铺公告列表
                </div>
            </div>
            <!-- /header -->
            <el-tabs
                v-model="filterData.verify"
                @tab-click="getTableData(1)"
            >
                <el-tab-pane
                    label="全部"
                    name="99"
                />
                <el-tab-pane
                    label="待审核"
                    name="0"
                />
                <el-tab-pane
                    label="审核已通过"
                    name="1"
                />
                <el-tab-pane
                    label="审核不通过"
                    name="-1"
                />
            </el-tabs>
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">店铺名称：</p>
                    <el-input
                        placeholder="请输入店铺名称"
                        v-model="filterData.shop_keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">提交时间：</p>
                    <el-date-picker
                        v-model="createTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="small"
                        style="width: 400px"
                        value-format="timestamp"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">审核时间：</p>
                    <el-date-picker
                        v-model="verifyTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="small"
                        style="width: 400px"
                        value-format="timestamp"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                </div>
            </div>
            <!--筛选-->
            <!-- table -->
            <el-table
                :data="tableData"
                height="100%"
                style="width: 100%;"
                ref="tempLateName"
            >
                <el-table-column
                    label="序号"
                    type="index"
                    align="center"
                    width="80"
                />
                <el-table-column
                    label="店铺公告内容"
                    align="left"
                    width="300"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div v-if="scope.row.verify === 1 || scope.row.verify === -1">{{ scope.row.content }}</div>
                        <div v-else>{{ scope.row.content_submit }}</div>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="shop_title"
                    label="店铺名称"
                    align="center"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    label="提交时间"
                    show-overflow-tooltip
                    align="center"
                >
                    <template slot-scope="scope">
                        {{ scope.row.submit_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="审核时间"
                    show-overflow-tooltip
                    align="center"
                >
                    <template slot-scope="scope">
                        {{ scope.row.verify_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="审核状态"
                    show-overflow-tooltip
                    align="center"
                >
                    <template slot-scope="scope">
                        <div v-if="scope.row.verify === 0">待审核</div>
                        <div v-if="scope.row.verify === 1">审核通过</div>
                        <div v-if="scope.row.verify === -1">审核不通过</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="操作"
                    align="left"
                    width="200"
                >
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            v-if="scope.row.verify === 0"
                            @click="showPassDialog(scope.row.shop_no)"
                        >
                            审核通过
                        </el-button>
                        <el-button
                            type="text"
                            v-if="scope.row.verify !== -1"
                            @click="showRejectDialog(scope.row)"
                        >
                            审核不通过
                        </el-button>
                        <el-button
                            type="text"
                            v-if="scope.row.verify === -1 && scope.row.verify_fail_reason"
                            @click="showRejectDialog(scope.row, 1)"
                        >
                            驳回原因
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- /table -->

            <!-- 分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
            <!-- /分页 -->
        </div>
        <!-- 驳回弹窗 -->
        <reject-dialog
            ref="rejectDialog"
            :visible.sync="rejectDialog"
            :reason-detail="reasonDetail"
            :maxlength="100"
            @confirm="handleExamine('reject', $event)"
        />
        <!-- /驳回弹窗 -->
    </div>
</template>

<script>
import rejectDialog from '@/components/dialog/reject-dialog';

export default {
    name: 'ShopNoticeVerify',
    data() {
        return {
            filterData: {
                // 状态
                verify: '99',
                shop_keyword: '',
                submit_start_time: '',
                submit_end_time: '',
                verify_start_time: '',
                verify_end_time: ''
            },
            tableData: [],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            createTimeRange: [],
            verifyTimeRange: [],
            // 拒绝弹窗
            rejectDialog: false,
            shop_no: '',
            // 驳回原因详情
            reasonDetail: '',
            authResult: {}
        };
    },
    components: {
        rejectDialog
    },
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '商城'}, {title: 'APP店铺公告列表'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },
    watch: {
        createTimeRange(value) {
            this.filterData.submit_start_time = value ? value[0] / 1000 : '';
            this.filterData.submit_end_time = value ? value[1] / 1000 : '';
            this.getTableData(1);
        },
        verifyTimeRange(value) {
            this.filterData.verify_start_time = value ? value[0] / 1000 : '';
            this.filterData.verify_end_time = value ? value[1] / 1000 : '';
            this.getTableData(1);
        }
    },
    methods: {

        /**
         * @description 获取公告列表数据
         * @param page
         */
        getTableData(page) {

            let params = {...this.filterData};

            params.page_id = page || this.page.now_page;
            params.verify = Number(params.verify);

            this.$post('/student/shop_announce%5Cget_list', params, resp => {
                if (resp.code === 1) {
                    this.tableData = resp.data.list;
                    this.page = resp.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 审核通过提示弹窗
         * @param no
         */
        showPassDialog(no) {
            if(!this.authResult.auth_verify) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            this.$confirm('是否确认通过该店铺公告信息审核?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.shop_no = no;
                this.handleExamine('pass');
            });
        },

        /**
         * 驳回弹窗
         * @param type - 0填写驳回原因  1回显原因
         * @param row
         */
        showRejectDialog(row, type = 0) {
            if(type === 1) {
                // 回显
                this.$refs.rejectDialog.title = '驳回原因';
                this.reasonDetail = row.verify_fail_reason;
                this.rejectDialog = true;
            } else {
                if(!this.authResult.auth_verify) {
                    this.$notify({
                        title: '提示',
                        message: '请联系管理员添加权限',
                        type: 'warning',
                        duration: 2000
                    });
                    return false;
                }
                // 填写
                this.shop_no = row.shop_no;
                this.$refs.rejectDialog.title = '审核驳回';
                this.$refs.rejectDialog.reason = '您好，请重新填写店铺公告信息';
                this.reasonDetail = '';
                this.rejectDialog = true;
            }
        },

        /**
         * 审核公告请求
         * @param action - pass通过  reject拒绝
         * @param reason - 拒绝原因
         *        verify 1通过 -1不通过
         */
        handleExamine(action, reason = '') {
            let params = {
                shop_no: this.shop_no,
                verify_fail_reason: reason,
                verify: action === 'pass' ? 1 : -1
            };

            this.$post('/student/shop_announce%5Cverify', params, resp => {
                if (resp.code === 1) {

                    this.rejectDialog = false;
                    this.$notify({
                        title: '成功',
                        message: '操作成功',
                        duration: 2000,
                        type: 'success'
                    });
                    this.getTableData();
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 表格数据过滤函数
         * @param row
         * @param column
         * @param val
         * @returns {string|*}
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },
    }
};
</script>

<style scoped lang="less">
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0 24px 12px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*el-tabs*/

        /deep/ .el-tabs {

            .el-tabs__nav-wrap {
                height: 54px;
                padding-left: 24px;

                .el-tabs__nav-scroll {
                    .el-tabs__nav {
                        height: 54px;
                        line-height: 54px;
                    }
                }
            }

            .el-tabs__header {
                margin-bottom: 0;
            }
        }

        /*筛选*/

        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 24px 24px 0;

            .header-new-box {
                display: flex;
                align-items: center;
                color: #606266;
                white-space: nowrap;
                margin-right: 32px;
                margin-bottom: 24px;

                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }

        /* 分页 */

        .pagination-wrapper {
            padding: 10px 32px;

            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }

        /deep/ .el-dialog__header {
            padding-top: 10px;
            box-shadow: 0px 1px 0px 0px rgba(233, 233, 233, 1);
            display: flex;
            align-items: center;
            background: #FAFAFA;
            border-radius: 4px 4px 0 0;

            .el-dialog__title {
                font-weight: 500;
                color: #333;
                font-size: 14px;
            }

            .el-icon-close:before {
                color: rgb(194, 194, 194);
                font-size: 17px;
                font-weight: bold;
            }

            .el-dialog__headerbtn {
                top: 14px;
            }
        }

        /deep/ .el-textarea__inner {
            resize: none;
        }
    }

    /*弹窗*/

    .form-title {
        margin: 16px 0;
        font-size: 14px;
        color: #333;
        position: relative;
    }

    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow: 0px 1px 0px 0px rgba(233, 233, 233, 1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;

        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }

        .el-icon-close:before {
            color: rgb(194, 194, 194);
            font-size: 17px;
            font-weight: bold;
        }

        .el-dialog__headerbtn {
            top: 14px;
        }
    }

    /deep/ .el-textarea__inner {
        resize: none;
    }

    /*驳回原因弹窗*/

    .reject-reason {
        display: flex;
        flex-direction: column;
        align-items: center;

        .reason-wrapper {
            width: 100%;
            padding: 24px;
            background: #FBFBFB;
            border-radius: 4px;
            border: 1px solid #EEEEEE;
            line-height: 20px;
            margin: 4px 34px;
        }

        .know-btn {
            width: 120px;
            margin-top: 30px;
        }
    }

    .reject-dialog {
        /deep/ .el-dialog__footer {
            text-align: center;
            padding: 0;
            padding-bottom: 30px;
            margin-top: 6px;
        }
        /deep/ .el-dialog__body {
            padding: 24px 64px;
        }
    }
}
</style>


